#define  _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
/*int main()
{
	long long ret = 0;
	for (int i = 1012; i > 1; i--)
	{
		if ( 2024%i == 0)
		{
			int flag = 1;
			for (int j = 2; j < i; j++)
			{
				if (i % j == 0)
				{
					flag = 0;
					break;
				}

			}
			if (flag)
			{
				ret = ret + i;
			}

		}
	}
	cout << ret;*/

	/*for (int i = 2024; i >= 2; i--)
	{
		int flag = 1;
		for (int j = 2; j * j <= i; j++)
		{
			if (i % j == 0)
			flag = 0;
		}
		if (flag)
		{
			cout << i;
			break;
		}
	}*/
	/*int count = 1;
	for (int i = 3;; i++)
	{
		
		int flag = 1;
		for (int j = 2; j <= i && j <= 2024; j++)
		{
			if (i % j == 0 && 2024 % j == 0)
				flag = 0;
		}
		if (flag)
		{
			count++;
			if (count == 2024)
			{
				cout << i;
				break;
			}
		}
	}
	
	return 0;
}*/
#include<string.h>
#include<string>
#include<vector>
	using namespace std;

	/*int main()
	{
		string s1, s2, s3, s4;
		cin >> s1 >> s2 >> s3 >> s4;

		vector<string> arr(4);
		arr[0] = s1, arr[1] = s2, arr[2] = s3, arr[3] = s4;
		string max;
		for (int i = 0; i <= 3; i++)
		{
			for (int j = 0; j <= 3; j++)
			{
				for (int k = 0; k <= 3; k++)
				{
					for (int l = 0; l <= 3; l++)
					{
						if (i != j && i != k && i != l && j != k && j != l && k != l)
						{
							
							string tmp;
							tmp += arr[i];
							tmp += arr[j];
							tmp += arr[k];
							tmp += arr[l];
							if (max.empty())
							{
								max = tmp;
							}
							else if (strcmp(tmp.c_str(), max.c_str())<0)
							{
								max = tmp;
							}
						}
					}

				}
			}
		}
		cout << max << endl;
		return 0;
	}*/
	const int N = 10001;
	//int a[N], b[N];
	int main()
	{
		int ret = 0;
		
		int n,  m;
		vector<int> a, b;
		
		cin >> n;
		a.reserve(n);
		int x;
		for (int i = 0; i < n; i++)
		{
			cin >> x;
			a.push_back(x);
		}
		cin >> m;
		b.reserve(m);
		for (int i = 0; i < m; i++)
		{
			cin >> x;
			b.push_back(x);
		}
		while (!a.empty() && !b.empty())
		{
			if (a[0] <= b[0])
			{
				reverse(a.begin(), a.end());
				a.pop_back();
				reverse(a.begin(), a.end());
				ret++;
				reverse(b.begin(), b.end());
				b.pop_back();
				reverse(b.begin(), b.end());
			}
			else {
				reverse(b.begin(), b.end());
				b.pop_back();
				reverse(b.begin(), b.end());
			}
		}
		cout << ret;
		return 0;
		
	}